package models

import "gorm.io/gorm"

// 点赞表
type Like struct {
	gorm.Model
	UserId  int `gorm:"type:int;comment:'用户id'"`
	VideoId int `gorm:"type:int;unique;comment:'视频id'"`
}

func (l *Like) TableName() string {
	return "like"
}

// 点赞
func (l *Like) AddLike(db *gorm.DB) error {
	return db.Create(&l).Error
}

// 取消点赞
func (l *Like) DelLike(db *gorm.DB) error {
	return db.Unscoped().Delete(&l).Error
}

// 判断点赞状态
func (l *Like) GetLikeStatus(db *gorm.DB, userId, videoId int64) error {
	return db.Model(&Like{}).Where("user_id = ? and video_id = ?", userId, videoId).Limit(1).Find(&l).Error
}
